package cn.wenhaha.app.data.bean;

import cn.hutool.core.util.StrUtil;
import cn.wenhaha.common.db.bean.SysDataSource;
import cn.wenhaha.datasource.IDataSourcePlugin;

/**
 * 数据源插件信息
 * --------
 *
 * @author ：wyndem
 * @Date ：Created in 2022-07-14 22:29
 */
public class DataPlugin {

    private SysDataSource dataSource;
    private IDataSourcePlugin dataSourcePlugin;

    private DataPlugin(SysDataSource dataSource, IDataSourcePlugin dataSourcePlugin) {
        this.dataSource = dataSource;
        this.dataSourcePlugin = dataSourcePlugin;
    }

    public static DataPlugin build(SysDataSource dataSource, IDataSourcePlugin dataSourcePlugin) {
        return new DataPlugin(dataSource,dataSourcePlugin);
    }



    public String getName(){
        return dataSource.getName();
    }


    public SysDataSource getDataSource() {
        return dataSource;
    }

    public IDataSourcePlugin getDataSourcePlugin() {
        return dataSourcePlugin;
    }

    public String getAddPage(){
        return  getDataSource().getAddPage();
    }

    public String getCode(){
        return  getDataSource().getCode();
    }




    public String getUpdatePage(){
        return  getDataSource().getUpdatePage();
    }



    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DataPlugin that = (DataPlugin) o;
        if(that.getDataSource() == null && getDataSource() != null) return  false;
        if(that.getDataSource() == null && getDataSource() == null) return  true;

        return  StrUtil.equals(getDataSource().getId(),that.getDataSource().getId());
    }

    @Override
    public int hashCode() {
        int result = dataSource != null ? dataSource.hashCode() : 0;
        result = 31 * result + (dataSourcePlugin != null ? dataSourcePlugin.hashCode() : 0);
        return result;
    }
}
